package org.jeecg.modules.workflow.convert.definition;

import org.flowable.bpmn.model.UserTask;
import org.jeecg.common.util.collection.CollectionUtils;
import org.jeecg.common.workflow.vo.definition.rule.BpmTaskAssignRuleCreateReqVO;
import org.jeecg.common.workflow.vo.definition.rule.BpmTaskAssignRuleRespVO;
import org.jeecg.common.workflow.vo.definition.rule.BpmTaskAssignRuleUpdateReqVO;
import org.jeecg.modules.workflow.entity.BpmTaskAssignRule;

import java.util.List;
import java.util.Map;

public interface BpmTaskAssignRuleConvert {


    default List<BpmTaskAssignRuleRespVO> convertList(List<UserTask> tasks, List<BpmTaskAssignRule> rules) {
        Map<String, BpmTaskAssignRule> ruleMap = CollectionUtils.convertMap(rules, BpmTaskAssignRule::getTaskDefinitionKey);
        // 以 UserTask 为主维度，原因是：流程图编辑后，一些规则实际就没用了。
        return CollectionUtils.convertList(tasks, task -> {
            BpmTaskAssignRuleRespVO respVO = convert(ruleMap.get(task.getId()));
            if (respVO == null) {
                respVO = new BpmTaskAssignRuleRespVO();
                respVO.setTaskDefinitionKey(task.getId());
            }
            respVO.setTaskDefinitionName(task.getName());
            return respVO;
        });
    }

    BpmTaskAssignRuleRespVO convert(BpmTaskAssignRule bean);

    BpmTaskAssignRule convert(BpmTaskAssignRuleCreateReqVO bean);

    BpmTaskAssignRule convert(BpmTaskAssignRuleUpdateReqVO bean);

    List<BpmTaskAssignRule> convertList2(List<BpmTaskAssignRuleRespVO> list);

}
